package com.db.domain.bank;

import java.io.Serializable;

public class Client implements Serializable {
    private String name;
    private Gender gender;
    private Account account;

    public Client(String name, Gender gender, Account account) {
        this.name = name;
        this.gender = gender;
        this.account = account;
    }

    public Account getAccount() {
        return account;
    }

    public String getName() {
        return name;
    }

    public String getClientSalutation() {
        return gender.getPrefix() + name;
    }

    @Override
    public String toString() {
        return new StringBuilder(getClientSalutation()).
                append(" : balance = ").append(account.getBalance()).
                toString();
    }


    /**
     *
     * @return true if two clients have same gender and name
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Client)) return false;

        Client client = (Client) o;

        return gender == client.gender && !(name != null ? !name.equals(client.name) : client.name != null);

    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (gender != null ? gender.hashCode() : 0);
        return result;
    }
}
